package com.omesoft.hksnore.util.dialog;

/**
 * Created by Omesoft on 2017/2/21.
 */

import android.content.Context;
import android.os.Handler;
import android.util.Log;


/**
 * 调用自定义进度对话框式具类MyProgressBarDialog
 *
 * @author Omesoft
 *
 */
public class MyProgressBarDialogUtil {
    public static MyProgressBarDialog dialog;

    /**
     * 显示进度对话框
     *
     * @param context
     * @param msgId
     */
    public static void show(Context context, int msgId) {
        Log.e("show", "show: " );
        dialog = new MyProgressBarDialog(context);
        dialog.setMsg(msgId);
        dialog.show();
    }

    public static  MyProgressBarDialog getDialog(Context context, String msgId){
        dialog = new MyProgressBarDialog(context);
        dialog.setMsg(msgId);
        return  dialog;
    }

    /**
     * 显示进度对话框
     *
     * @param context
     * @param context
     */
    public static void show(Context context) {
        dialog = new MyProgressBarDialog(context);
        dialog.show();
    }

    /**
     * 关闭进度对话框
     */
    public static void dismiss() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    /**
     * 设置进度对话框显示文字提示
     */
    public static void setMsg(int msgId) {
        if (dialog != null) {
            dialog.setMsg(msgId);
        }
    }

    /**
     * 关闭已弹出的对话框，再弹出一个新的进度对话框
     *
     * @param msgId
     */

    public static void dismiss2Msg(int msgId) {
        Log.e("show","dismiss2Msg");
        if (dialog==null){
            return;
        }
        dialog.setMsg(msgId);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                // dialog.dismiss();
                dismiss();
            }
        }, 1000);
    }

    /**
     * 关闭已弹出的对话框，再弹出一个新的进度对话框
     *
     * @param content
     */

    public static void dismiss2Msg(int title, int content) {
        dialog.setFinishText(title, content);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                dismiss();
            }
        }, 1000);
    }

    public static void dismiss2Msg(String title, String content) {
        dialog.setFinishText(title, content);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                dismiss();
            }
        }, 1000);
    }

    // public static void dismiss2Msg(int msgId) {
    // dialog.setMsg(msgId);
    // if (dialog != null) {
    // dialog.dismiss();
    // }
    // }

    /**
     * 关闭已弹出的对话框，再弹出一个新的进度对话框
     *
     * @param msg
     */
    public static void dismiss2Msg(String msg) {

        if (dialog==null){
            return;
        }
        dialog.setMsg(msg);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                // dialog.dismiss();
                dismiss();
            }
        }, 2000);
    }

    public static void remove() {
        if (dialog != null)
            dialog.cancel();
    }
}

